package com.hdf.etdemo.view.badger;

import com.hdf.easytools.base.EasyToolsActivity;
import com.hdf.easytools.view.badger.BadgeView;
import com.hdf.etdemo.R;
import com.hdf.etdemo.R.layout;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.BounceInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.Toast;

public class BadGerActivity extends EasyToolsActivity {
	Button btnPosition;
	Button btnColour;
	Button btnAnim1;
	Button btnAnim2;
	Button btnCustom;
	Button btnClick;
	
	
	BadgeView badge1;
	BadgeView badge2;
	BadgeView badge3;
	BadgeView badge4;
	BadgeView badge5;
	BadgeView badge6;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_bad_ger);
		/** 设置标题显示 */
		this.TitleVisib(0, 1, 1, 0, 0);
		/** 绑定标题点击事件 */
		this.TitleClick(0, 1, 0, 0, 0);
		/** 设置标题样式ʽ */
		this.TitleStyle(null, R.drawable.et_back, "徽章控件", null, 0);
		
		// *** default badge ***
        
				View target = findViewById(R.id.default_target);
				BadgeView badge = new BadgeView(this, target);
				badge.setText("1");
				badge.show();
		        
		        // *** set position ***
				
		        btnPosition = (Button) findViewById(R.id.position_target);
		        badge1 = new BadgeView(this, btnPosition);
		        badge1.setText("12");
		        /**
		         * setBadgePosition()设置徽章的显示位置，有以下几个可选值：     
     				POSITION_TOP_LEFT 左上角
     				POSITION_TOP_RIGHT 右上角，默认
     				POSITION_BOTTOM_LEFT  左下角
     				POSITION_BOTTOM_RIGHT  右下角
     				POSITION_CENTER  中心
		         */
		        badge1.setBadgePosition(BadgeView.POSITION_CENTER);
		        btnPosition.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						badge1.toggle();
					}
				});
		        
		        // *** badge/text size & colour ***
		        
		    	btnColour = (Button) findViewById(R.id.colour_target);
		    	badge2 = new BadgeView(this, btnColour);
		    	badge2.setText("New!");
		    	badge2.setTextColor(Color.BLUE);
		    	badge2.setBadgeBackgroundColor(Color.YELLOW);
		    	badge2.setTextSize(12);
		    	btnColour.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						badge2.toggle();
					}
				});
		    	
		    	// *** default animation ***
		    	
		    	btnAnim1 = (Button) findViewById(R.id.anim1_target);
		        badge3 = new BadgeView(this, btnAnim1);
		        badge3.setText("84");
		        btnAnim1.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						badge3.toggle(true);
					}
				});
		    	
		        // *** custom animation ***
		        
		    	btnAnim2 = (Button) findViewById(R.id.anim2_target);
		        badge4 = new BadgeView(this, btnAnim2);
		    	badge4.setText("123");
		    	badge4.setBadgePosition(BadgeView.POSITION_TOP_LEFT);
		    	badge4.setBadgeMargin(15, 10);
		    	badge4.setBadgeBackgroundColor(Color.parseColor("#A4C639"));
		    	btnAnim2.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						TranslateAnimation anim = new TranslateAnimation(-100, 0, 0, 0);
				        anim.setInterpolator(new BounceInterpolator());
				        anim.setDuration(1000);
				    	badge4.toggle(anim, null);
					}
				});
		        
		    	// *** custom background ***
		    	
		        btnCustom = (Button) findViewById(R.id.custom_target);
		        badge5 = new BadgeView(this, btnCustom);
		        badge5.setText("37");
		        badge5.setBackgroundResource(R.drawable.badge_ifaux);
		    	badge5.setTextSize(16);
		    	btnCustom.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						badge5.toggle(true);
					}
				});
		    	
		    	// *** clickable badge ***
		    	
		    	btnClick = (Button) findViewById(R.id.click_target);
		    	badge6 = new BadgeView(this, btnClick);
		    	badge6.setText("click me");
		    	badge6.setBadgeBackgroundColor(Color.BLUE);
		    	badge6.setTextSize(16);
		    	badge6.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						Toast.makeText(BadGerActivity.this, "clicked badge", Toast.LENGTH_SHORT).show();
					}
				});
		    	btnClick.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						badge6.toggle();
					}
				});
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.left_img:
			finish();
			break;

		default:
			break;
		}
	}
}
